﻿@{
    Layout = "~/Views/Shared/_Form.cshtml";
}
@model Raffles.OA.Data.Menu 
<link href="~/Content/plugin/ztree/css/metroStyle/metroStyle.min.css" rel="stylesheet" />
<link href="~/Content/plugin/ztree/core/treeSelect.css" rel="stylesheet" /> 
<form class="form-horizontal m" role="form">
    <div class="form-group">
        <label class="col-sm-2 control-label">父级菜单</label>
        <div class="col-sm-10">
            <div class="treeSelect"></div>
            @Html.Hidden("TreeId", Model.ParentId)
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">菜单类型<font class="red">*</font></label>
        <div class="col-sm-10">
            @Html.DropDownList("Type", null, "请选择菜单类型", htmlAttributes: new { @class = "form-control select2 required" })
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">菜单名称<font class="red">*</font></label>
        <div class="col-sm-10">
            @Html.TextBoxFor(model => model.Name, new { @class = "form-control required", @placeholder = "请输入菜单名称" })
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">菜单Icon</label>
        <div class="col-sm-10">
            @Html.TextBoxFor(model => model.Icon, new { @class = "form-control", @placeholder = "请输入菜单Icon" })
            <div class="ms-parent" style="width: 100%;">
                <div class="icon-drop animated flipInX" style="display: none;max-height:150px;overflow-y:auto">
                    @Html.Partial("Icon")
                </div>
            </div>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">访问地址</label>
        <div class="col-sm-10">
            @Html.TextBoxFor(model => model.UrlAddress, new { @class = "form-control", @placeholder = "请输入访问地址" })
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">权限标识</label>
        <div class="col-sm-10">
            @Html.TextBoxFor(model => model.Authorize, new { @class = "form-control", @placeholder = "请输入权限标识" })
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">显示顺序<font class="red">*</font></label>
        <div class="col-sm-10">
            @Html.TextBoxFor(model => model.DisplayOrder, new { @class = "form-control required", @type = "number", @min = "0", @placeholder = "请输入显示顺序" })
        </div>
    </div>
</form>
<script src="~/Content/plugin/ztree/js/jquery.ztree.all.min.js"></script>
<script src="~/Content/plugin/ztree/core/treeSelect.js"></script>
<script>
    var id = frame.request("id");
    $(function () { 

        $("#Icon").focus(function () {
            $(".icon-drop").show();
        });
        $(".icon-drop").find(".ico-list i").on("click", function () {
            $('#Icon').val($(this).attr('class'));
            $(".icon-drop").hide();
        }); 

        frame.ajax({
            url: '@Url.Content("/Manage/Menu/GetMenuTreeSelect")',
            type: "get", 
            success: function (result) {
                if (result.success) {
                    $(".treeSelect").treeSelect({
                        data: result.data,
                        placeholder: "请选择父级菜单",
                        inputId: "txt"
                    })
                    if (@Model.Id> 0 &&@Model.ParentId> 0) {
                        zTreeObj = $.fn.zTree.getZTreeObj("_treeDomtxt");
                        zTreeObj.selectNode(zTreeObj.getNodeByParam("id", @Model.ParentId));
                        $('#txt').val(zTreeObj.getNodeByParam("id", @Model.ParentId).name);
                    }
                }
            }
        });  

        $(document).click(function (e) {
            var e = e ? e : window.event;
            var tar = e.srcElement || e.target;
            if (!$(tar).hasClass('form-control')) {
                if ($(".icon-drop").is(':visible')) {
                    $(".icon-drop").hide();
                }
            }
        });

    })
    function saveForm() { 
        if ($('form').validate().form()) { 
            frame.ajax({
                url: '@Url.Content("/Manage/Menu/SaveForm")',
                type: "post",
                data: $('form').formSerialize(),
                success: function (obj) {
                    if (obj.success) {
                        frame.msgSuccess(obj.message); 
                        parent.searchTreeGrid();
                        frame.closeDialog(); 
                    }
                    else {
                        frame.msgError(obj.message);
                    }
                }
            });
        }
    }
</script>